package com.leetcode;

import com.common.TreeNode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test {

    public static void main(String[] args) {
        Integer[] array = {1,2,3,4,null,2,4,null,null,4};
        long prepow = 0;
        for (int i = 0; i < array.length; i++) {
           // System.out.print(array[i]+"\t");
            int n = (int)Math.ceil((i)%2==0?i+1:i/2D);
            System.out.println(n);
            long pow = (long)Math.pow(2, n);
            if(prepow != pow){
                prepow = pow;
                System.out.println();
            }
        }

    }

    Map<String,Integer> map = new HashMap<>();
    List<TreeNode> list = new ArrayList<>();

    public List<TreeNode> findDuplicateSubtrees(TreeNode node){

        computerNode(node);
        return list;
    }

    public String computerNode(TreeNode node){
        if(node == null){
            return "";
        }
        String key = node.val + "";
        String left = computerNode(node.left);
        String right = computerNode(node.right);
        if(left == null || !left.equals("")){
            key += "-l"+left;
        }
        if(right == null || !right.equals("")){
            key += "-r"+right;
        }
        int val = map.getOrDefault(key,0)+1;
        map.put(key,val);
        if(val == 2){
            list.add(node);
        }
        return key;

    }
}
